﻿
    using Chain.BLL;
    using Chain.Model;
    using System;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    public partial class index : Page
    {
        public string Domain = PubFunction.curParameter.strDoMain;
        protected string lineLinkurl = "";
        protected string memID = "0";
        protected Random r = new Random();

        public string WeiXinAppID = PubFunction.curParameter.strWeiXinAppID;
        public string WeiXinShopName = PubFunction.curParameter.strWeiXinShopName;

        protected void Page_Load(object sender, EventArgs e)
        {
            string memWeiXinCard = string.Empty;
            if (base.Request["MemWeiXinCard"] != null)
            {
                memWeiXinCard = base.Request["MemWeiXinCard"].ToString();
            }
            if (!string.IsNullOrEmpty(memWeiXinCard))
            {
                Chain.Model.Mem mem = new Chain.BLL.Mem().GetMemByWeiXinCard(memWeiXinCard);
                if (mem != null)
                {
                    base.Response.Cookies.Add(new HttpCookie("uid", mem.MemID.ToString()));
                    this.lineLinkurl = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}_uri={1}/ReceptionPage/register.aspx&response_type=code&scope=snsapi_base&state={2}#wechat_redirect", PubFunction.curParameter.strWeiXinAppID, this.Domain, mem.MemID);
                }
                base.Response.Redirect("index.aspx");
            }
            else
            {
                HttpCookie wxMem = base.Request.Cookies["uid"];
                if (wxMem != null)
                {
                    if (Regex.IsMatch(wxMem.Value, @"^\d+$"))
                    {
                        this.memID = wxMem.Value;
                    }
                    this.lineLinkurl = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}_uri={1}/ReceptionPage/register.aspx&response_type=code&scope=snsapi_base&state={2}#wechat_redirect", PubFunction.curParameter.strWeiXinAppID, this.Domain, this.memID);
                }
                else
                {
                    base.Response.Redirect("login.aspx");
                }
                this.txtMemID.Value = this.memID;
            }
        }
    }


